<template>
  <b-container fluid class="my-md-3">
    <b-row class="animated bounceInDown">
      <b-img :src="avatar" center rounded="circle" alt="avatar" width="280" height="280" thumbnail/>
    </b-row>
    <b-row class="text-center  animated bounceInUp">
      <b-col>
        <br>
        <h1>{{ username }}</h1>
        <br>
      </b-col>
    </b-row>
    <b-row class="text-center animated bounceInUp">
      <b-col>
        <h6>创建时间：{{ createAt }}</h6>
      </b-col>
    </b-row>
    <b-row class="text-center animated bounceInUp">
      <b-col/>

      <b-col>
        <b-link>
          <h3>{{ topicCount }}</h3>
          <h5>帖子数</h5>
        </b-link>
      </b-col>
      <b-col>
        <b-link>
          <h3>{{ commentCount }}</h3>
          <h5>评论数</h5>
        </b-link>
      </b-col>
      <b-col/>
    </b-row>
    <b-row class="text-center animated bounceInUp my-3">
      <b-col>
        <b-card header="个人资料">
          <b-card-text>{{ info }}</b-card-text>
        </b-card>
      </b-col>
    </b-row>
  </b-container>
</template>

<script>
import axios from "axios";

export default {
  name: "Home",
  data() {
    return {
      avatar: "",
      username: "Charly",
      createAt: "",
      commentCount: 0,
      topicCount: 0,
      info: "这个人没有填个人资料",
      uid: this.$store.state.uid
    }
  },
  created() {

    console.log(this.$route.query.uid === undefined)
    if (this.$route.query.uid === undefined)
      var url = "/dev_api/users/info";
    else
      url = "/dev_api/users/info/" + this.$route.query.uid;
    axios({
      method: "get",
      url: url,
      headers: {
        "Authorization": this.$store.state.token
      }
    })
        .then(response => {
          if (response.data.code === 200) {
            console.log(response.data.data)
            this.username = response.data.data.username
            this.commentCount = response.data.data.commentCount
            this.createAt = response.data.data.createAt
            this.topicCount = response.data.data.topicCount
            if (response.data.data.bio !== null)
              this.info = response.data.data.bio
            this.avatar = response.data.data.avatar
          } else {
            console.log("请求失败:", response.data)
          }
        }).catch(error => {
      console.log(error)
    })
  }
}
</script>

<style scoped>

</style>